import React, { Component } from 'react';
import ReactEcharts from 'echarts-for-react'
import moment from 'moment';

class Profit extends Component {
    componentDidUpdate() {
        this.getOption();
    }
    getOption = () => {
        const { menuList } = this.props;
        let menuLists= deviceDetails(menuList)
        let option = {
            tooltip: {
                trigger: 'axis',
                show: true,
                formatter: "{a} <br/>{b}: {c} ({d}%)",
                axisPointer: {  // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            legend: {

                top: '5%',
                left: '4%',
                orient: 'vertical',
            },
            series: [
                {
                    name: 'Access From',
                    type: 'pie',
                    radius: ['40%', '60%'],
                    avoidLabelOverlap: false,
                    label: {
                        show: false,
                        position: 'center'
                    },
                    emphasis: {
                        label: {
                            show: true,
                            fontSize: '15',
                            fontWeight: 'bold'
                        }
                    },
                    labelLine: {
                        show: false
                    },
                    data: menuLists,
                }
            ]
        }
        return option
    }
    render() {
        return (
            <div>
                <ReactEcharts
                    option={this.getOption()}
                    style={{ width: '30vw', height: '30vh' }}
                />
            </div>
        )


    }

}

export default Profit;
function deviceDetails(arry = []) {
    let newdata = [];
    for (let i = 0; i < arry.length; i++) {
        let obj = {};
        obj.value = arry[i].menuTotal;
        obj.name = arry[i].menuName;

        newdata.push(obj);
    }
    return newdata;
}